<?


class CTRLfabric extends CONTROL {

	function __construct( $vars ) {
		global $Object;
		
		$this->_addvars( $vars );

		if( $this->action != "list" )
			$Object = $this->create_object();
		
	}

#	Edit Object.
	function filter_edit() {
		global $DB, $Engine, $Object;
		
		$type = $this->vars->type;
		
		return "
		ref.seed([
			new Element( 'h1' ).update( \"Beheer $type '". ( $Object->hasName()? $Object->get( "name" ) : $Object->id ) . "'\" ),
			new Textfield({ descr:'name $type', type:'$type', parentid:{$Object->id}, textid:". $Object->get( "nameid" ) .", values:". json_encode( $Engine->text->filter( $Object->get( "nameid" ) )) ." }),
			new Htmlfield({ descr:'text $type', type:'$type', parentid:{$Object->id}, textid:". $Object->get( "textid" ) .", values:". json_encode( $Engine->text->filter($Object->get( "textid" ), 'long' )) ." }),
			new Dropbox({ descr:'Files', type:'media.file', parenttype:'$type', action:'win', blank:'add file', id:{$Object->id}, uptype:'file', floats:". $this->filter_media( 'media.file' ) ." }),
			new Options({ descr:'Opties', floats: [
				new Shift({ type:'$type', descr:'Is public', value:{$Object->get( 'active' )}, field:'active', objid:{$Object->id} }),
				new Ajxfield({ type:'$type', descr:'link', objid:{$Object->id}, field:'meta.link', value:'{$Object->get('link')}' }),
				new Rank({ type:'$type', descr:'Rank', value:{$Object->get( 'rank' )}, field:'rank', objid:{$Object->id} })
			]})
		]);";

		
	}

#	Render media floats
	function filter_media( $objtype ) {
		global $DB, $Object;
		
		$result = array();
		
		if( $images = $Object->media->filter( $objtype ))
			foreach( $images as $img ) {
				$result[] = array( "id"=> $img['ID'], "type"=> $objtype, "name"=> $objtype, "list"=> array( $img['ID'], json_decode( $img[ 'meta' ])->raw ));
			}
		
		return json_encode( $result );
	}

}


?>